﻿using System;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace POS
{
    public class Food : Order, IOrderable, IRenderable
    {
        public Food(string name, double price, double rating, FoodOptions.Size size, FoodOptions.Type type)
            : base(name, price, rating)
        {
            this.Size = size;
            this.Type = type;
        }

        // public string Name { get; protected set; }
        // public double Price { get; private set; }
        public FoodOptions.Size Size { get; private set; }
        public FoodOptions.Type Type { get; private set; }

        public double OrderPrice()
        {
            return this.Price;
        }

        public bool Orderable()
        {
            return true;
            // Check for ing.s
        }

        public override string ToString()
        {
            return String.Format("Drink '{0}' Type '{1}' Size '{2}'", this.Name, this.Type, this.Size);
        }

        public override int GetHashCode()
        {
            return this.Name.GetHashCode() + this.Type.GetHashCode() + this.Size.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if (obj is Food)
            {
                Food drink = obj as Food;
                if (this.GetHashCode() == drink.GetHashCode())
                {
                    return true;
                }
                return false;
            }
            return false;
        }

        private string CalculateNeededStarsFromRating()
        {
            StringBuilder sb = new StringBuilder();
            int counter = 0;

            while (counter != Math.Ceiling(this.Rating))
            {
                counter++;
                sb.Append("*");
            }

            return sb.ToString();
        }

        //Needs to be checked!
        public UIElement Render()
        {
            var container = new UniformGrid();
            container.HorizontalAlignment = HorizontalAlignment.Stretch; // Maybe Right alignment
            container.Columns = 1;

            var nameTextBlock = new TextBlock();
            nameTextBlock.Text = this.Name;
            nameTextBlock.FontSize = 14;
            container.Children.Add(nameTextBlock);

            var priceTextBlock = new TextBlock();
            priceTextBlock.Text = this.Price.ToString();
            priceTextBlock.FontSize = 14;
            container.Children.Add(priceTextBlock);

            var ratingTextBlock = new TextBlock();
            

            ratingTextBlock = new TextBlock();
            ratingTextBlock.Text = CalculateNeededStarsFromRating();
            ratingTextBlock.FontSize = 14;
            container.Children.Add(ratingTextBlock);

            return container;
        }
    }
}
